package net.wanho.zaixian.cms.controller;

import com.alibaba.fastjson.JSONObject;
import net.wanho.zaixian.cms.service.CmsTemplateService;
import net.wanho.zaixian.pojo.cms.CmsTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.List;

@RestController
public class CmsTemplateController {

    @Resource
    CmsTemplateService cmsTemplateService;

    @GetMapping("/cms/template/list")
    public List<CmsTemplate> templateList(){
       return cmsTemplateService.getAllTemplate();
    }
    @PostMapping("cms/template/upload")
    public JSONObject addFile(@RequestBody Object object) throws UnsupportedEncodingException {
        String fileId = cmsTemplateService.templateUpload(object);
        JSONObject jsonObject = new JSONObject();
        if(fileId !=null && !"".trim().equals(fileId.trim())){
            jsonObject.put("success",true);

            return jsonObject;
        }
        jsonObject.put("success",false);
        return jsonObject;
    }

}

